#ifndef COOLPOOL_SIMULATION_SIMOBJECTS_COLLISIONDETECTOR_H_
#define COOLPOOL_SIMULATION_SIMOBJECTS_COLLISIONDETECTOR_H_

#include "Collision.h"
#include "Constants.h"
#include "Entity.h"
#include "SimObjectsExceptions.h"

namespace coolpool
{
	// Base class for all the collision detectors, every dynamic
	// object needs to have one. It is used by the collision detection engine.
	class CollisionDetector
	{
	public:
		virtual ~CollisionDetector()
		{

		}
		// Detects the collision between two entities .
		// Returns the collision if it happened, NULL otherwise.
		// It must setup the two objects, collision_normal, collision_point and the type. The time is added in CollisionTimeFinder.
		virtual Collision * detect(Entity * entity1, Entity * entity2) const throw (UnexpectedInputException) = 0;

	protected:

		// Sets the type of the collision, based on MIN_COLL_VELOCITY
		inline void setCollisionType(double vel_rel, Collision * col) const
		{
			if (vel_rel > MIN_COLLISION_VELOCITY)
				col->type = MOVINGAWAY;
			else if (vel_rel > -MIN_COLLISION_VELOCITY)
				col->type = RESTING_CONTACT;
			else
				col->type = INTERPENETRATION;
		}
	};
}
#endif
